#!/usr/bin/python3
# -*- coding: UTF-8 -*-
import json

import requests
from requests import session
import requests
from requests.auth import HTTPBasicAuth

session = requests.session()

baseUrl = ""
username = ""
password = ""
def mqlist():
    mqListUrl = baseUrl + "/api/queues?page=1&page_size=500&name=&use_regex=false&sort=messages&sort_reverse=true&pagination=false"
    resp = requests.get(mqListUrl, auth=HTTPBasicAuth(username, password))
    res = resp.content.decode('utf-8')
    res_json = json.loads(res)
    return res_json['items']
    pass

def detail(mq_list):
    for mq in mq_list:
        # print(mq)
        # if mq['consumers'] == 0 or mq['messages'] > 0:
        if mq['messages'] > 0:
            print(mq['name'], mq['consumers'],  mq['messages'])
        # mq_detail_url = baseUrl + "/api/queues/" + mq['vhost'] + "/" + mq['name']
        # resp = requests.get(mq_detail_url, auth=HTTPBasicAuth(username, password))
        # res = resp.content.decode('utf-8')
        # res_json = json.loads(res)
        # print(res_json)
    pass


def main():
    mq_list = mqlist()
    detail(mq_list)


if __name__ == '__main__':
    main()
